package labuladong.chapter0;

public class ListNode {
    int val;
    ListNode next;

    ListNode(int val) {
        this.val = val;
    }

    /**
     * 通过数组创建链表
     */
    public static ListNode createLinkedList(int[] array) {
        if (array == null || array.length == 0) {
            return null;
        }
        ListNode head = new ListNode(array[0]);
        ListNode currentNode = head;
        for (int i = 1; i < array.length; i++) {
            ListNode next = new ListNode(array[i]);
            currentNode.next = next;
            currentNode = next;
        }
        return head;
    }
}
